<?php 

namespace app\index\model;
use think\Model;

class blog extends Model{
	//获取文章第一张图片
	 public function getImgAttr($value,$data)
    {
    	$pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg]))[\'|\"].*?[\/]?>/";
		$content = $data['content'];  //文章内容
		preg_match_all($pattern,$content,$matchContent);
		if(isset($matchContent[1][0])){
			return str_replace('../../../',dirname($_SERVER['SCRIPT_NAME']),$matchContent[1][0]); 
		}else{
			return dirname($_SERVER['SCRIPT_NAME']).'/static/index/images/noimg.png'; 

		}
	}
	public function getClassAttr($value,$data)
    {
    	$cid = $data['cid'];
    	$class = db('category')->where('id',$cid)->find();
    	return $class['name'];
	}
}

 ?>